<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <base-input v-model="value"></base-input>
    <base-input :value="value" @input="value = $event"></base-input>
    {{value}}
    <hr>

    <base-checkbox v-model="checked"></base-checkbox>
    {{checked}}
  </div>

  <!-- <script src="../../node_modules/vue/dist/vue.min.js"></script> -->
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js"></script>
  <script>
    Vue.component("base-input", {
      props: ['value'],
      methods: {
        handleInput(e) {
          this.$emit("input", e.target.value)
        }
      },
      template: `<input type='text' :value="value" @input="handleInput"/>`
    })
    Vue.component("base-checkbox", {
      // 配置model，因为 v-mode 默认值匹配 value + input事件
      model: {
        prop: 'checked',
        event: 'change'
      },
      props: ['checked'],
      methods: {
        handleChange(e) {
          this.$emit("change", e.target.checked)
        }
      },
      template: `<div>
        <input type='checkbox' :checked="checked" @change="handleChange" /> 选我
      </div>`
    })

    const vue = new Vue({
      el: "#app",
      components: ["base-input", 'base-checkbox'],
      data: {
        value: "hello...",
        checked: true
      }
    })


  </script>
</body>

</html>